
{extend name=".././view/list.html" /}
{block name="jsset"}

{/block}
{block name="nav"}
<span class="layui-breadcrumb">
	<a href="">教务管理</a>
	<a href="">班级管理</a>
	<a><cite>班级列表</cite></a>
</span>
{/block}
{block name="search"}
<div class="layui-form-item">
	<label for="school" class="layui-form-label" style="height: 100%">学校</label>
	<div class="layui-input-block">
		{php}
		$schoollist = schoolXueduan('小学','初中');
		{/php}
		{volist name="schoollist" id="vo"}
		<input type="radio" name="school_id" title="{$vo.jiancheng}" value="{$vo.id}" lay-skin="primary" {eq name="i" value="1"}checked{/eq}>
		{/volist}
	</div>
</div>
<div class="layui-form-item" style="margin-bottom: 0;">
	<label for="ruxuenian" class="layui-form-label" style="height: 100%">年级</label>
	<div class="layui-input-block">
    <input type="radio" name="ruxuenian" title="无" value="" lay-skin="primary" checked="checked">
    {php} $njlist = nianJiNameList(); {/php}
    {volist name="njlist" id="vo"}
		<input type="radio" name="ruxuenian" title="{$vo}" value="{$key}" lay-skin="primary">
		{/volist}
	</div>
</div>
{/block}
{block name="table"}
<table id="tabledemo" lay-filter="mytable" lay-size="sm"></table>
{/block}
{block name="myjs"}
<!-- 表格上面按钮模板 -->
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-danger" lay-event="dels">
			<i class="iconfont">&#xe69d;</i> 批量删除
		</button>
		<button class="layui-btn" lay-event="add">
			<i class="iconfont">&#xe6b9;</i> 添加
		</button>
	</div>
</script>
<!-- 记录操作按钮模板 -->
<script type="text/html" id="barDemo">
	<a class="layui-btn-xs" lay-event="detail" title="成绩"><i class="layui-icon layui-icon-chart-screen"></i></a>
	<a class="layui-btn-xs" lay-event="banzhuren" title="设置班主任"><i class="layui-icon layui-icon-username"></i></a>
	<a class="layui-btn-xs" lay-event="befo" title="前移"><i class="layui-icon">&#xe603;</i></a>
	<a class="layui-btn-xs" lay-event="end" title="后移"><i class="layui-icon">&#xe602;</i></a>
	<a class="layui-btn-xs" lay-event="del" title="删除"><i class="layui-icon">&#xe640;</i></a>
</script>
<!-- 表格操作 -->
<script>
	// 设置列
	options.cols=[[ //表头
	{type:'checkbox', fixed: 'left'},
	{field: 'id', title: 'ID', minWidth:100,sort: true},
	{field: 'banjiTitle', title: '班级名称', minWidth:100,templet:function(d){
	    var str='';
	    if(d.grade && d.ban)
	    {
	      str = d.grade + d.ban;
	    }
	    return str;
	  }},
	{field: 'alias', title: '别名', minWidth:60, edit:'text'},
	{field: 'banzhuren', title: '现任班主任',sort: true, minWidth:60,templet:function(d){
		var str='';
		if(d.bzr)
		{
			str = d.bzr;
		}
		return str;
	}},
	{field: 'school', title: '单位名称',sort: true, minWidth:240,templet:function(d){
		var str='';
		if(d.glSchool)
		{
			str = d.glSchool.title;
		}
		return str;
	}},
	{field: "ruxuenian",title: '入学年',sort: true},
	{field: 'paixu', title: '排序', sort: true},
	{field:"gl_student_count",title: '学生数',sort: true},
	{field: 'status', title: '状态',templet:'#status', sort: true},
	{field: 'id', title: '操作',toolbar: '#barDemo',minWidth:180}
	]];
	// 设置查询条件
	options.where = {
		ruxuenian:$("input[name='ruxuenian']:checked").val()
	}

	// 提交搜索条件后重载表格
	layui.use(['table','cjgl'],function(){
		var table = layui.table
		cjgl = layui.cjgl;
      //表头工具栏事件
      table.on('toolbar(mytable)', function(obj){
      	switch(obj.event){
      		case 'dels':
            layer.msg('暂时不允许删除');
            break;
      			var checkStatus = table.checkStatus('mytable'); //idmytable 即为基础参数 id 对应的值
      			cjgl.delAll(checkStatus,'/teach/banji/delete','mytable');
      			break;
      		case 'add':
      			cjgl.add('添加班级','/teach/banji/create','600','300');
      			break;
      		};
      	});

      //监听行工具条
      table.on('tool(mytable)', function(obj){
      	var data = obj.data; //获得当前行数据
      	var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
      	var tr = obj.tr; //获得当前行 tr 的DOM对象
      	switch(layEvent){
	      case 'detail':// 查看
            parent.xadmin.add_tab(obj.data.banjiTitle  +'－考试成绩','/teach/banjicj/index/'+obj.data.id,'','',true);
            break;
          case 'befo':// 前移
  	        yidong(this,'/teach/banji/yidong/'+data.id,-1);
  	        break;
	      case 'end':// 后移
  	        yidong(this,'/teach/banji/yidong/'+data.id,1);
  	        break;
	      case 'del':// 删除
            layer.msg('暂时不允许删除');
            break;
  	        cjgl.del(obj,"/teach/banji/delete");
	         break;
	      case 'edit':// 编辑
  	        cjgl.add('编辑班级','/teach/banji/edit/'+obj.data.id,'600','300');
  	        break;
  	      case 'banzhuren':   //编辑
  	        cjgl.addTab('班主任','/teach/banzhuren/index/'+obj.data.id,'','',true);
  	        break;
       };
     });


    // 单元格编辑
    table.on('edit(mytable)',function(obj){
      // 声明变量
      var value = obj.value
        ,rowdata = obj.data;

      // 修改服务器数据
      $.ajax({
        url:"/teach/banji/alias",
        type:'PUT',
        data:{
            "id":rowdata.id,
            'alias':value
        },
        success:function(result,obj){
            layer.msg(result.msg);
        },
        error:function(result){
            layer.msg('数据扔半道啦。',function(){});
        },
      });
    });

  });

	/*班级移动*/
	function yidong(obj,url,caozuo){
		layer.confirm('确认要移动班级位置吗？',function(index){
			$.ajax({
				type: 'POST',
				url: url,
				data: {
					cz:caozuo,
				},
				dataType: 'json',
				success: function(data){

					if(data.val == 0){
						layer.alert(data.msg);
						return true;
					}

					var yd = $(obj).parents("tr");
					var mytitle = $(yd).find('td[data-field="banjiTitle"]').children('div');
					var paixu = $(yd).find('td[data-field="paixu"]').children('div');
					mytitle.text(data.title);
					paixu.text(data.paixu);

					layer.alert(data.msg);
					return true;
				},
				error:function(data) {
					layer.alert('移动失败');
				},
			});
		});
	}

</script>
{/block}
